#include<iostream>
#include<vector>
#include<fstream>
#include<istream>
#include<string>
using namespace std;
void readFloat(vector<float> &om1, vector<vector<float>> &wm1,
                vector<float> &om2, vector<vector<float>> &wm2)
{
    ifstream fin("6om_wm_sm.txt");
    if(!fin.is_open())
    {
        cout << "Open Failed." << endl;
        return;
    }
    string s;
    getline(fin, s);
    for(int i = 0; i < 257; ++i)
    {
        fin >> om1[i];
        cout << om1[i] << ' ';
    }
    cout << endl;
    getline(fin, s);
    getline(fin, s);
    getline(fin, s);
    for(int i = 0; i < 257; ++i)
    {
        for(int j = 0; j < 10; ++j)
        {
            fin >> wm1[i][j];
            cout << wm1[i][j] << ' ';
        }
        cout << endl;
    }
    getline(fin, s);
    getline(fin, s);
    getline(fin, s);
    getline(fin, s);
    getline(fin, s);
    getline(fin, s);
    for(int i = 0; i < 257; ++i)
    {
        fin >> om2[i];
        cout << om2[i] << ' ';
    }
    cout << endl;
    getline(fin, s);
    getline(fin, s);
    getline(fin, s);
    for(int i = 0; i < 257; ++i)
    {
        for(int j = 0; j < 10; ++j)
        {
            fin >> wm2[i][j];
            cout << wm2[i][j] << ' ';
        }
        cout << endl;
    }
}
vector<float> omMulwm(vector<float> om, vector<vector<float>> wm, vector<float> &sm)
{
    for(int i = 0; i < 257; ++i)
    {
        //cout << i << endl;
        for(int j = 0; j < 10; ++j)
        {
            //cout << i << ' ' << j << endl;
            sm[j] += om[i] * wm[i][j];
        }
    }
    return sm;
}
vector<float> omMulwmDou(vector<float> om, vector<vector<float>> wm, vector<float> &sm)
{
    for(int i = 0; i < 257; ++i)
    {
        //cout << i << endl;
        for(int j = 0; j < 10; ++j)
        {
            //cout << i << ' ' << j << endl;
            double a = om[i];
            double b = wm[i][j];
            double c = a * b;
            sm[j] += c;
        }
    }
    return sm;
}
int main()
{
    vector<float> om1(257);
    vector<vector<float>> wm1(257, vector<float>(10));
    vector<float> om2(257);
    vector<vector<float>> wm2(257, vector<float>(10));
    readFloat(om1, wm1, om2, wm2);
    vector<float> sm1(10, 0.0);
    vector<float> sm2(10, 0.0);
    sm1 = omMulwmDou(om1, wm1, sm1);
    sm2 = omMulwmDou(om2, wm2, sm2);
    for(int i = 0; i < 10; ++i)
    {
        cout << sm1[i] << ' ';
    }
    cout << endl;
    for(int i = 0; i < 10; ++i)
    {
        cout << sm2[i] << ' ';
    }
    cout << endl;
    return 0;
}
